//
//  HOCommentTableViewCell.m
//  微度报修
//
//  Created by foguo-mac-1 on 7/4/16.
//  Copyright © 2016 WeiDu. All rights reserved.
//

#import "HOCommentTableViewCell.h"
#import "HOImageMgr.h"
#import "UIImageView+WebCache.h"
#import "HOUtils.h"

@interface HOCommentTableViewCell()
@property(nonatomic, retain)UIImageView *headerImgView;
@property(nonatomic, retain)UILabel 	*titleLbl;
@property(nonatomic, retain)UILabel 	*timeLbl;
@property(nonatomic, retain)UILabel 	*locationLbl;
@property(nonatomic, retain)UILabel 	*statusTitleLbl;
@property(nonatomic, retain)UILabel 	*statusLbl;
@property(nonatomic, retain)UILabel 	*assignLbl;
@property(nonatomic, retain)UILabel 	*contentLbl;
@property(nonatomic, assign)CGFloat		height;
@end;

@implementation HOCommentTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)setEntity:(HOCommentEntity *)entity
{
	if(entity == nil)
	{
		self.height = 0;
		return;
	}
	[self.headerImgView sd_setImageWithURL:[NSURL URLWithString:entity.headPic] placeholderImage:[[HOImageMgr sharedInstance] getDefaultImage]];
	[self.headerImgView.layer setMasksToBounds:YES];
	self.headerImgView.layer.cornerRadius = self.headerImgView.frame.size.width / 2;
	self.titleLbl.text = [NSString stringWithFormat:@"%@", entity.userName];
	self.titleLbl.font = [UIFont systemFontOfSize:14];
	self.titleLbl.frame = CGRectMake(self.titleLbl.frame.origin.x,
									 self.titleLbl.frame.origin.y,
									 [HOUtils getScreenWidth] - self.titleLbl.frame.origin.x - self.timeLbl.frame.size.width,
									 22);
	self.timeLbl.text = [HOUtils getDateFromTimeInterval:entity.createTime * 1000];
	self.timeLbl.textAlignment = NSTextAlignmentRight;
	self.timeLbl.font = [UIFont systemFontOfSize:((IS_IPHONE_4_SCREEN) || (IS_IPHONE_5_SCREEN)) ? 12 : 13];
	self.statusTitleLbl.text = NSLocalizedString(@"当前状态：", @"当前状态：");
	[self.statusTitleLbl sizeToFit];
	self.statusLbl.frame = CGRectMake(self.statusTitleLbl.frame.origin.x + self.statusTitleLbl.frame.size.width,
									  self.statusTitleLbl.frame.origin.y,
									  100,
									  22);
	self.statusLbl.textColor = [HOUtils getOrderColorWithStatus:entity.status];
	self.statusLbl.text = [HOUtils getDescribtionWithStatus:entity.status];
	[self.statusLbl sizeToFit];
	self.locationLbl.text = [NSString stringWithFormat:@"%@：%@", NSLocalizedString(@"科室", @"科室"), [HOUtils getValideString:entity.departmentName]];
	
	self.assignLbl.text = [NSString stringWithFormat:@"%@%@", NSLocalizedString(@"任务分配给：", @"任务分配给："), [HOUtils getValideString:entity.doneName]];
	self.contentLbl.frame = CGRectMake(self.titleLbl.frame.origin.x,
									   self.assignLbl.frame.origin.y + 22 + 2,
									   self.frame.size.width - 1 * HO_HORIZONAL_PADDING - 40 + 2 * HO_HORIZONAL_PADDING,
									   60);
	if(self.isExtraAssistant)
	{self.contentLbl.frame = CGRectMake(self.titleLbl.frame.origin.x,
										self.assignLbl.frame.origin.y + 2 + 2,
										self.frame.size.width - 1 * HO_HORIZONAL_PADDING - 40 + 2 * HO_HORIZONAL_PADDING,
										60);
	}
	self.contentLbl.text = entity.content;
	[self.contentLbl sizeToFit];
	self.assignLbl.hidden = self.isExtraAssistant;
	self.height = self.contentLbl.frame.size.height + HO_HORIZONAL_PADDING + self.contentLbl.frame.origin.y;
}

- (CGFloat )getCellHeight
{
	return self.height;
}

- (void)initWithWidth:(CGFloat)width
{
	self.headerImgView = [[[UIImageView alloc]
						  initWithFrame:CGRectMake(HO_HORIZONAL_PADDING,
												   HO_HORIZONAL_PADDING,
												   40,
												   40)] autorelease];
	[self.contentView addSubview:self.headerImgView];

	
	CGFloat x = 40 + 2 * HO_HORIZONAL_PADDING;
	
	self.titleLbl = [[[UILabel alloc]
					initWithFrame:CGRectMake(x,
											 HO_HORIZONAL_PADDING,
											 width - 160 - x,
											 22)] autorelease];
	[self.contentView addSubview:self.titleLbl];
	self.titleLbl.textColor = TEXT_COLOR_181818;
	self.titleLbl.font = [UIFont systemFontOfSize:15];
	self.timeLbl = [[[UILabel alloc]
				   initWithFrame:CGRectMake(width - 160,
											self.titleLbl.frame.origin.y,
											150,
											22)] autorelease];
	self.timeLbl.textAlignment = NSTextAlignmentRight;
	[self.contentView addSubview:self.timeLbl];
	self.timeLbl.textColor = TEXT_COLOR_999999;
	self.timeLbl.font = [UIFont systemFontOfSize:13];
	
	self.locationLbl = [[[UILabel alloc]
					   initWithFrame:CGRectMake(x,
												self.titleLbl.frame.origin.y + 22 + 2,
												width - 2 * HO_HORIZONAL_PADDING - x,
												22)] autorelease];
	self.locationLbl.numberOfLines = 3;
	[self.contentView addSubview:self.locationLbl];
	self.locationLbl.textColor = TEXT_COLOR_181818;
	self.locationLbl.font = [UIFont systemFontOfSize:13];
	self.statusTitleLbl = [[[UILabel alloc]
					   initWithFrame:CGRectMake(self.titleLbl.frame.origin.x,
												self.locationLbl.frame.origin.y + 22 + 2,
												width - 2 * HO_HORIZONAL_PADDING - x,
												22)] autorelease];
	[self.contentView addSubview:self.statusTitleLbl];
	self.statusTitleLbl.textColor = TEXT_COLOR_181818;
	self.statusTitleLbl.text = NSLocalizedString(@"当前状态：", @"当前状态：");
	self.statusTitleLbl.font = [UIFont systemFontOfSize:13];
	
	self.statusLbl = [[[UILabel alloc]
					 initWithFrame:CGRectMake(self.statusTitleLbl.frame.origin.x + self.statusTitleLbl.frame.size.width,
											  self.statusTitleLbl.frame.origin.y - 3,
											  width - 2 * HO_HORIZONAL_PADDING - x,
											  22)] autorelease];
	[self.contentView addSubview:self.statusLbl];
	self.statusLbl.textColor = [UIColor redColor];
	self.statusLbl.font = [UIFont systemFontOfSize:13];
	
	self.assignLbl = [[[UILabel alloc]
					 initWithFrame:CGRectMake(self.titleLbl.frame.origin.x,
											  self.statusLbl.frame.origin.y + 16 + 2,
											  width - 2 * HO_HORIZONAL_PADDING - x,
											  22)] autorelease];
	[self.contentView addSubview:self.assignLbl];
	self.assignLbl.textColor = TEXT_COLOR_666666;
	self.assignLbl.font = [UIFont systemFontOfSize:13];
	self.contentLbl = [[[UILabel alloc]
				   initWithFrame:CGRectMake(self.titleLbl.frame.origin.x,
											self.assignLbl.frame.origin.y + 22 + 2,
											width - 1 * HO_HORIZONAL_PADDING - x,
											60)] autorelease];
	self.contentLbl.numberOfLines = 0;
	[self.contentView addSubview:self.contentLbl];
	self.contentLbl.textColor = TEXT_COLOR_999999;
	self.contentLbl.font = [UIFont systemFontOfSize:13];

}

- (void)dealloc
{
	self.headerImgView = nil;
	self.titleLbl = nil;
	self.timeLbl = nil;
	self.locationLbl = nil;
	self.statusLbl = nil;
	self.assignLbl = nil;
	self.contentLbl = nil;
	[super dealloc];
}

@end
